home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1995 June
/
MacFormat 25.iso
/
Shareware City
/
Developers
/
ICProgKit1.0
/
Source
/
API Source
/
ICAPI.p
next >
Wrap
Text File
|
1994-11-27
|
10KB
|
269 lines
unit ICAPI;
interface
uses
{$ifc undefined THINK_Pascal}
Types, Files,
{$endc}
ICTypes;
function ICStart (var inst: ICInstance; creator: OSType): ICError;
(* call at application initialisation *)
function ICStop (inst: ICInstance): ICError;
(* call at application termination *)
function ICFindConfigFile (inst: ICInstance; count: integer; folders: ICDirSpecArrayPtr): ICError;
(* count is the number of ICDirSpecs that are valid in folders *)
(* searches the specified folders first, then backs out to preferences folder *)
(* don't you worry about how it finds the file (; *)
(* you can pass nil to folders if count is 0 *)
function ICSpecifyConfigFile (inst: ICInstance; config: FSSpec): ICError;
(* for use *only* by Internet Configuration application *)
function ICGetSeed (inst: ICInstance; var seed: longint): ICError;
(* returns current seed for prefs file *)
(* this seed changes every time a preference is modified *)
(* poll this to detect preference changes by other applications *)
function ICGetPerm (inst: ICInstance; var perm: ICPerm): ICError;
(* returns the permissions currently associated with this file *)
(* mainly used by overriding components, applications normally *)
(* know what permissions they have *)
function ICBegin (inst: ICInstance; perm: ICPerm): ICError;
(* start reading/writing the preferences *)
(* must be balanaced by a ICEnd *)
(* do not call WaitNextEvent between this pair *)
(* specify either icReadOnlyPerm or icReadWritePerm *)
(* note that this may open resource files and leave them open until ICEnd *)
function ICGetPref (inst: ICInstance; key: Str255; var attr: ICAttr; buf: Ptr; var size: longint): ICError;
(* this routine may be called without a ICBegin/ICEnd pair, in which case *)
(* it implicitly calls ICBegin(inst, icReadOnlyPerm *)
(* given a key string, returns the attributes and the (optionally) the data for a preference *)
(* key must not be the empty string *)
(* if buf is nil then no data fetched and incoming size is ignored*)
(* size must be non-negative, is size of allocated space for data at buf *)
(* attr and size and always set on return *)
(* size is actual size of data (if key present) *)
(* attr is pref attributes *)
(* if icTruncatedErr then everything is valid, except you lost some data, size is size of real data*)
(* on other errors, attr is ICattr_no_change and size is 0 *)
function ICSetPref (inst: ICInstance; key: Str255; attr: ICAttr; buf: Ptr; size: longint): ICError;
(* this routine may be called without a ICBegin/ICEnd pair, in which case *)
(* it implicitly calls ICBegin(inst, icReadWritePerm *)
(* given a key string, sets the attributes and the data for a preference (either is optional) *)
(* key must not be the empty string *)
(* if buf is nil then no data stored and size is ignored, used for setting attr *)
(* size must be non-negative, is size of the data at buf to store *)
(* icPermErr if ICBegin was given icReadOnlyPerm *)
(* icPermErr if current attr is locked, new attr is locked and buf <> nil *)
function ICCountPref (inst: ICInstance; var count: longint): ICError;
(* count total number of preferences *)
(* if error then count is 0 *)
function ICGetIndPref (inst: ICInstance; n: longint; var key: Str255): ICError;
(* return the key of the Nth preference *)
(* n must be positive *)
(* icPrefNotFoundErr if n is beyond the last preference *)
function ICDeletePref (inst: ICInstance; key: Str255): ICError;
(* delete the preference specified by key *)
(* key must not be the empty string *)
(* preference specified by key must be present *)
(* icPrefNotFoundErr if it isn't *)
function ICEnd (inst: ICInstance): ICError;
(* stop reading/writing the preferences *)
function ICDefaultFileName (inst: ICInstance; var name: Str63): ICError;
(* return the default file name *)
(* the component calls this routine to set up the default internet configuration file name*)
(* this allows this operation to be intercepted by a component that has captured us *)
(* it currently gets it from the component resource file *)
(* the glue version is hardwired *)
function ICGetComponentInstance (inst: ICInstance; var component_inst: univ Ptr): ICError;
(* returns noErr and the component instance that we're talking to, if we're using the component *)
(* returns an error and nil if we're doing it with glue *)
(* univ Ptr rather than ComponentInstance so that you don't need Components.p *)
(* in order to use this file *)
implementation
uses
{$ifc undefined THINK_Pascal}
Components, Memory,
{$endc}
ICCAPI, ICRAPI;
function ICStart (var inst: ICInstance; creator: OSType): ICError;
var
err: ICError;
begin
inst := NewPtr(sizeof(ICRRecord));
err := MemError;
if err = noErr then begin
err := ICCStart(ICRRecordPtr(inst)^.instance, creator);
if err <> noErr then begin
err := ICRStart(ICRRecordPtr(inst)^, creator);
end; (* if *)
if err <> noErr then begin
DisposePtr(inst);
inst := nil;
end; (* if *)
end; (* if *)
ICStart := err;
end; (* ICStart *)
function ICStop (inst: ICInstance): ICError;
var
err, err2: ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
err := ICCStop(ICRRecordPtr(inst)^.instance);
end
else begin
err := ICRStop(ICRRecordPtr(inst)^);
end; (* if *)
DisposePtr(inst);
ICStop := err;
end; (* ICStop *)
function ICFindConfigFile (inst: ICInstance; count: integer; folders: ICDirSpecArrayPtr): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICFindConfigFile := ICCFindConfigFile(ICRRecordPtr(inst)^.instance, count, folders);
end
else begin
ICFindConfigFile := ICRFindConfigFile(ICRRecordPtr(inst)^, count, folders);
end; (* if *)
end; (* ICFindConfigFile *)
function ICSpecifyConfigFile (inst: ICInstance; config: FSSpec): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICSpecifyConfigFile := ICCSpecifyConfigFile(ICRRecordPtr(inst)^.instance, config);
end
else begin
ICSpecifyConfigFile := ICRSpecifyConfigFile(ICRRecordPtr(inst)^, config);
end; (* if *)
end; (* ICSpecifyConfigFile *)
function ICGetSeed (inst: ICInstance; var seed: longint): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICGetSeed := ICCGetSeed(ICRRecordPtr(inst)^.instance, seed);
end
else begin
ICGetSeed := ICRGetSeed(ICRRecordPtr(inst)^, seed);
end; (* if *)
end; (* ICGetSeed *)
function ICGetPerm (inst: ICInstance; var perm: ICPerm): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICGetPerm := ICCGetPerm(ICRRecordPtr(inst)^.instance, perm);
end
else begin
ICGetPerm := ICRGetPerm(ICRRecordPtr(inst)^, perm);
end; (* if *)
end; (* ICGetPerm *)
function ICBegin (inst: ICInstance; perm: ICPerm): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICBegin := ICCBegin(ICRRecordPtr(inst)^.instance, perm);
end
else begin
ICBegin := ICRBegin(ICRRecordPtr(inst)^, perm);
end; (* if *)
end; (* ICBegin *)
function ICGetPref (inst: ICInstance; key: Str255; var attr: ICAttr; buf: Ptr; var size: longint): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICGetPref := ICCGetPref(ICRRecordPtr(inst)^.instance, key, attr, buf, size);
end
else begin
ICGetPref := ICRGetPref(ICRRecordPtr(inst)^, key, attr, buf, size);
end; (* if *)
end; (* ICGetPref *)
function ICSetPref (inst: ICInstance; key: Str255; attr: ICAttr; buf: Ptr; size: longint): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICSetPref := ICCSetPref(ICRRecordPtr(inst)^.instance, key, attr, buf, size);
end
else begin
ICSetPref := ICRSetPref(ICRRecordPtr(inst)^, key, attr, buf, size);
end; (* if *)
end; (* ICSetPref *)
function ICCountPref (inst: ICInstance; var count: longint): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICCountPref := ICCCountPref(ICRRecordPtr(inst)^.instance, count);
end
else begin
ICCountPref := ICRCountPref(ICRRecordPtr(inst)^, count);
end; (* if *)
end; (* ICCountPref *)
function ICGetIndPref (inst: ICInstance; n: longint; var key: Str255): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICGetIndPref := ICCGetIndPref(ICRRecordPtr(inst)^.instance, n, key);
end
else begin
ICGetIndPref := ICRGetIndPref(ICRRecordPtr(inst)^, n, key);
end; (* if *)
end; (* ICGetIndPref *)
function ICDeletePref (inst: ICInstance; key: Str255): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICDeletePref := ICCDeletePref(ICRRecordPtr(inst)^.instance, key);
end
else begin
ICDeletePref := ICRDeletePref(ICRRecordPtr(inst)^, key);
end; (* if *)
end; (* ICDeletePref *)
function ICEnd (inst: ICInstance): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICEnd := ICCEnd(ICRRecordPtr(inst)^.instance);
end
else begin
ICEnd := ICREnd(ICRRecordPtr(inst)^);
end; (* if *)
end; (* ICEnd *)
function ICDefaultFileName (inst: ICInstance; var name: Str63): ICError;
begin
if ICRRecordPtr(inst)^.instance <> nil then begin
ICDefaultFileName := ICCDefaultFileName(ICRRecordPtr(inst)^.instance, name);
end
else begin
ICDefaultFileName := ICRDefaultFileName(ICRRecordPtr(inst)^, name);
end; (* if *)
end; (* ICDefaultFileName *)
function ICGetComponentInstance (inst: ICInstance; var component_inst: univ Ptr): ICError;
begin
component_inst := Ptr(ICRRecordPtr(inst)^.instance);
if component_inst = nil then begin
ICGetComponentInstance := badComponentInstance;
end
else begin
ICGetComponentInstance := noErr;
end; (* if *)
end; (* ICGetComponentInstance *)
end. (* ICAPI *)